//
//  ZGradientView.m
//  ZKit
//
//  Created by z on 2024/4/3.
//

#import "ZGradientView.h"

@interface ZGradientView ()

@property(nonatomic, strong) CAGradientLayer *gradientLayer;

@end


@implementation ZGradientView

+ (Class)layerClass {
    return [CAGradientLayer class];
}

- (CAGradientLayer *)gradientLayer {
    return (CAGradientLayer *)self.layer;
}

- (void)setColors:(NSArray<UIColor *> *)colors {
    NSMutableArray *arr = [NSMutableArray array];
    [colors enumerateObjectsUsingBlock:^(UIColor * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [arr addObject:(id)obj.CGColor];
    }];
    [self.gradientLayer setColors:arr];
}

- (NSArray<UIColor *> *)colors {
    NSMutableArray *arr = [NSMutableArray array];
    NSArray *layerColor = self.gradientLayer.colors;
    [layerColor enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [arr addObject: [[UIColor alloc] initWithCGColor:(__bridge CGColorRef _Nonnull)(obj)]];
    }];
    return arr;
}

- (void)setLocations:(NSArray<NSNumber *> *)locations {
    [self.gradientLayer setLocations:locations];
}

- (NSArray<NSNumber *> *)locations {
    return [self.gradientLayer locations];
}

- (void)setStartPoint:(CGPoint)startPoint {
    [self.gradientLayer setStartPoint:startPoint];
}

- (CGPoint)startPoint {
    return [self.gradientLayer startPoint];
}

- (void)setEndPoint:(CGPoint)endPoint {
    [self.gradientLayer setEndPoint:endPoint];
}

- (CGPoint)endPoint {
    return [self.gradientLayer endPoint];
}

- (void)setType:(CAGradientLayerType)type {
    [self.gradientLayer setType:type];
}

- (CAGradientLayerType)type {
    return self.gradientLayer.type;
}

@end
